package com.taoyibao.hongcanting.ui.home.delegate;

import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.taoyibao.hongcanting.R;
import com.taoyibao.hongcanting.base.delegate.BackToolbarDelegate;
import com.taoyibao.hongcanting.constant.CodeConstant;
import com.taoyibao.hongcanting.model.DishModel;
import com.taoyibao.hongcanting.ui.home.views.CountControllerArea;
import com.taoyibao.hongcanting.utils.CodeUtils;
import com.taoyibao.hongcanting.utils.GlideUtil;
import com.taoyibao.hongcanting.widget.HorizontalLineTextView;

/**
 * @author TangAnna
 * @description:
 * @date :${DATA} 15:24
 */
public class DishDetailsDelegate extends BackToolbarDelegate {
    private CountControllerArea mCountControllerArea;
    private ImageView mIvPic;//图片

    @Override
    public int getRootLayoutId() {
        return R.layout.activity_dish_details;
    }

    @Override
    public void initWidget() {
        super.initWidget();
        setTitle("菜品详情");
        mCountControllerArea = get(R.id.cca_dishDetail_countController);
        mCountControllerArea.setSource(CodeConstant.EVENT_SOURCE_MENU);

        mIvPic = get(R.id.iv_dishDetail_pic);
    }

    /**
     * 设置控制器的数据源
     *
     * @param dishModel
     */
    public void setDishModel(DishModel dishModel) {
        mCountControllerArea.setData(dishModel);
        //名称
        if (!TextUtils.isEmpty(dishModel.dish_name)) {
            ((TextView) get(R.id.tv_dishDetail_name)).setText(dishModel.dish_name);
        }
        //优惠价格
        ((TextView) get(R.id.tv_dishDetail_discountPrice)).setText(CodeUtils.formatAmountUnit(dishModel.dish_discount_price) + "/" + dishModel.dish_unit);
        //杠掉的原价
        ((HorizontalLineTextView) get(R.id.hltv_dishDetail_price)).setData(CodeUtils.formatAmountUnit(dishModel.dish_price) + "/" + dishModel.dish_unit);
        //食材
        ((TextView) get(R.id.tv_dishDetail_form)).setText("食材：" + dishModel.dish_form);
        //图片
        if (!TextUtils.isEmpty(dishModel.dish_pic)) {
            GlideUtil.getInstance().loadDefaultImage(getActivity(), dishModel.dish_pic, mIvPic);
        }
    }
}
